/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Dr.Tree
 * Created On : Dec 22, 2011  3:41:15 PM 
 * e-Mail : chatree@tis.co.th
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : promis.tested
 * File Name : RunningTested.java
 * TODO
 */
package promis.tested;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import javax.persistence.Column;
import org.apache.log4j.Logger;
import promis.db.connection.dbHelper;

/**
 * @author chatree
 *
 */
public class RunningTested {
	
	private static final Logger log = Logger.getLogger(RunningTested.class);

	/**
	 * 
	 */
	public RunningTested() {
		// TODO Auto-generated constructor stub
	}
	
//	private  String getRunning() throws SQLException, Exception{
//		return NewId("SP", "SYNC_MAT_MAS_SAP_INBOUND");		
//	}	
//	
//	public void ShowAllFieldValue(MmMatmasInb model){
//		//Get field name
//		Field[] fields = model.getClass().getDeclaredFields();		
//		for (int index = 0; index < fields.length; index++) 
//		{
//			String output = "Field - name: " + fields[index].getName() + " - value: ";
//			try
//			{
//				if (fields[index].getType().isInstance(Double.TYPE))
//					output += String.valueOf(fields[index].getDouble(this));
//				else
//					if (fields[index].getType().isInstance(Float.TYPE))
//						output += String.valueOf(fields[index].getFloat(this));
//					else
//						output += String.valueOf(fields[index].get(this));
//				System.out.println(output);
//			}
//			catch(IllegalAccessException e)
//			{
//				e.printStackTrace();
//				System.err.println(e.getMessage());
//			}
//		}
//	}
//	
//	
//
//
//	/**
//	 * @param args
//	 * @throws SQLException 
//	 * @throws NoSuchFieldException 
//	 * @throws SecurityException 
//	 * @throws IllegalAccessException 
//	 * @throws IllegalArgumentException 
//	 * @throws NoSuchMethodException 
//	 */
//	public static void main(String[] args) throws SQLException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, NoSuchMethodException {
//		
////		log.info(CommonService.AppsGetCurrentDateTime());
////		log.info(CommonService.sqlConvertStringToSQLDateTime("2011-11-25//15:40:25"));
//		
//		MmMatmasInb model = new MmMatmasInb();
//		
//		model.setArticleCode("sdiouruwirfjj XXXXXXXXXXXXXX ");
//		model.setArtiGrpCode("sdfjiooioer");
//		//new RunningTested().ShowAllFieldValue(model);
//		
//		
//		//Get the method named setDate.
//        //Class[] args2 = new Class[1];
//        //args2[0] = String.class;
//        //Method dateMethod =  model.getClass().getDeclaredMethod("getArticleCode", args2);
//        //System.out.println("Method found: " + dateMethod.toString());
//		
//		//Get Method
//		Method[] method_lst = model.getClass().getDeclaredMethods();
//		for (Method method : method_lst) {
//			log.info("Method Name : " + method.getName());
//			log.info("Method Default Value : " + method.getDefaultValue());			
//			
//			Annotation[] annotations = method.getDeclaredAnnotations();
//			for(Annotation annotation : annotations){
//			    if(annotation instanceof Column){
//			        Column myAnnotation = (Column)annotation;
//			        log.info("name: " + myAnnotation.name());
//			    }
//			}
//		}
//		
//		// create a java calendar instance
//		Calendar calendar = Calendar.getInstance();
//
//		// get a java.util.Date from the calendar instance.
//		// this date will represent the current instant, or "now".
//		java.util.Date now = calendar.getTime();
//		log.info(now);
//		
//		// a java current time (now) instance
//		java.sql.Timestamp currentTimestamp = new java.sql.Timestamp(now.getTime());
//		log.info(currentTimestamp);
//		String S = new SimpleDateFormat(DateFormats.DateFormat_yyyy_MM_dd_HH_mm_ss).format(currentTimestamp);
//		log.info("log timestamp format : "+ S);
//		
////		TODO Auto-generated method stub
////		RunningTested obj = new RunningTested();
////		Connection normal_connection = new dbHelper().getConn();
////		CommonService commServ = new CommonService(normal_connection);
//		
////		log.info(commServ.GetCurrentDBDate());
////		log.info(commServ.GetCurrentDBDateTime());
////		
////		String DATE_FORMAT = DateFormats.DateFormat_yyyy_MM_dd_HH_mm_ss; //"yyyyMMdd HH:mm:ss";
////	    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
////	    Calendar c1 = Calendar.getInstance(); // today
////	    System.out.println("Today is : " + sdf.format(c1.getTime()));
////	    
//	    
//		/*
//		Sequence seq = new Sequence(normal_connection);
//		try {
//			List<String> table_lst = seq.GetTable();
//			
//			if(table_lst != null) //Table Loop
//			{
//				List<Columns> column_lst = null;
//				for(String model : table_lst)
//				{
//					log.info(model + " : " + seq.IsExistsChecked(model));
//					column_lst = seq.GetColumns(model);
//					if(column_lst != null){
//						SyncSequence sequence = new SyncSequence();
//						sequence.setCompany(commServ.getCompanyCode());
//						sequence.setCreatedBy(commServ.getCreatedBy());
//						sequence.setCreatedOn(null);
//						sequence.setCurrentNext(Long.parseLong("10000"));
//						sequence.setDescription("");
//						sequence.setInCrement(Long.parseLong("1"));
//						sequence.setInternalKey(null);
//						sequence.setIsactive("Y");
//						sequence.setName(model);
//						
//					}
//				}
//			}
//			
//		} catch (SQLException e1) {
//			// TODO Auto-generated catch block
//			e1.printStackTrace();
//		}
//		
//		*/
//		try{			
////			obj.CloseConn();
////			log.info("Before Connection Status :" + obj.getConnStatus());
////			
////			for(int i = 0; i < 10000; i ++)			
////			{
////				log.info("Running Connection Status :" + obj.getConnStatus());
////				log.info("Running "+ i +" : " + obj.getRunning());
////				
////			}
//			
//			log.info("Running ...");
//			/*
//			Sequence seq = new Sequence(db.getConn());			
//			
//			for(int i = 0; i < 100000; i ++)
//			{
//				log.info("Running i = "+ i +" Connection Status :" + commServ.getConnStatus(db.getConn()));				
//				log.info("Running i = "+ i +" Connection Status :" + seq.GetNextSequence("SP", "SYNC_MAT_MAS_SAP_INBOUND"));			
//			}
//			*/
//			
//		}catch(Exception e)
//		{
//			log.error(e);			
//		}
//		
//		/*finally{
//			try {
//				//db.getConn().clearWarnings();
//				//db.getConn().close();
//				//log.ino("finally Connection Status :" + commServ.getConnStatus(db.getConn()));
//				//obj.CloseConn();
//				//log.info("After Connection Status :" + obj.getConnStatus());
//			} catch (SQLException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}*/
//
//	}
	
}
